﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Collections;
using MettleSystems.dashCommerce.Store;

[assembly: TagPrefix("MettleSystems.dashCommerce.Controls", "dashCommerce")]
namespace MettleSystems.dashCommerce.Controls
{
	[ToolboxData("<{0}:ProductAttributesList runat=\"server\" ID=\"productAttributesList\"></{0}:ProductAttributesList")]
	public class ProductAttributesList : DataList
	{
		public new AssociatedAttributeCollection DataSource
		{
			get
			{
				return base.DataSource as AssociatedAttributeCollection;
			}
			set
			{
				base.DataSource = value;
			}
		}

		private ITemplate _singleItemListTemplate;
		private ITemplate _singleLineTemplate;
		private ITemplate _multipleLineTemplate;
		private ITemplate _multipleItemsListTemplate;

		[TemplateContainer(typeof(DataListItem))]
		public ITemplate SingleItemListTemplate
		{
			get
			{
				return _singleItemListTemplate;
			}
			set
			{
				_singleItemListTemplate = value;
			}
		}

		[TemplateContainer(typeof(DataListItem))]
		public ITemplate SingleLineTemplate
		{
			get
			{
				return _singleLineTemplate;
			}
			set
			{
				_singleLineTemplate = value;
			}
		}

		[TemplateContainer(typeof(DataListItem))]
		public ITemplate MultipleLineTemplate
		{
			get
			{
				return _multipleLineTemplate;
			}
			set
			{
				_multipleLineTemplate = value;
			}
		}

		[TemplateContainer(typeof(DataListItem))]
		public ITemplate MultipleItemsListTemplate
		{
			get
			{
				return _multipleItemsListTemplate;
			}
			set
			{
				_multipleItemsListTemplate = value;
			}
		}

		protected override DataListItem CreateItem(int itemIndex, ListItemType itemType)
		{
			if (this.DataSource != null) {
				ITemplate itemTemplate = null;
				AssociatedAttribute aa = this.DataSource[itemIndex];
				switch (aa.AttributeTypeId) {
					case 1:
						itemTemplate = SingleItemListTemplate;
						break;
					case 2:
						itemTemplate = SingleLineTemplate;
						break;
					case 3:
						itemTemplate = MultipleLineTemplate;
						break;
					case 4:
						itemTemplate = MultipleItemsListTemplate;
						break;
				}
				if (itemType == ListItemType.Item)
					ItemTemplate = itemTemplate;
				if (itemType == ListItemType.AlternatingItem)
					AlternatingItemTemplate = itemTemplate;
			}
			return base.CreateItem(itemIndex, itemType);
		}
	}
}